<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'quickSearch', 'comSearch']"
            :quick-search-placeholder="t('Quick search placeholder', { fields: '标题' })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupForm />
    </div>
</template>

<script setup lang="ts">
import { ref, provide } from 'vue'
import baTableClass from '/src/utils/baTable'
import PopupForm from './popupForm.vue'
import Table from '/src/components/table/index.vue'
import TableHeader from '/src/components/table/header/index.vue'
import { defaultOptButtons } from '/src/components/table'
import { baTableApi } from '/src/api/common'
import { useI18n } from 'vue-i18n'

defineOptions({
    name: 'other/ad',
})

const { t } = useI18n()
const tableRef = ref()
const baTable = new baTableClass(
    new baTableApi('/admin/ad.ad/'),
    {
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('Id'), prop: 'id', align: 'center', operator: '=', operatorPlaceholder: t('Id'), width: 70 },
            { label: '信息分类', prop: 'category.name', align: 'center', operator: false, width: 150 },
            { label: '信息标题', prop: 'title', align: 'left', operator: 'LIKE', operatorPlaceholder: t('Fuzzy query') },
            { label: '缩略图', prop: 'thumb', align: 'center', render: 'image', operator: false, width: 200 },
            {
                label: t('State'),
                prop: 'status',
                align: 'center',
                render: 'tag',
                custom: { 0: 'info', 1: 'success' },
                replaceValue: { 0: '隐藏', 1: '显示' },
                width: 100
            },
            { label: t('Create time'), prop: 'create_time', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 },
            {
                label: t('Operate'),
                align: 'center',
                width: 150,
                render: 'buttons',
                buttons: defaultOptButtons(),
                operator: false,
            },
        ],
        dblClickNotEditColumn: [undefined]
    }
)

baTable.mount()
baTable.getIndex()

provide('baTable', baTable)
</script>

<style scoped lang="scss"></style>
